local class = require 'middleclass'
require 'util'

Player = class('Player')
function Player:initialize()
    self.x = lg:getWidth() / 2
    self.y = lg:getHeight() / 2
    self.r = 30
    self.speed = 100
    self.normalSpeed = 100
    self.dashedSpeed = 300
    self.w = self.r * 2
    self.h = self.r * 2
    self.rot = 0
    self.aabb = {}
    self.fireCD = 0.1
    self.dashCD = 1
    self.isDashed = false
    self.blinkDist = 100
    self.blinkCD = 0.1
    self.isblink = false
    self.color = {0, 0, 0}
    self.isChanged = false
    self.changeCD = 0.05
end

function Player:draw()
    lg.setColor(self.color)
    local vertices = {
        self.x + self.r * sin(self.rot),
        self.y - self.r * cos(self.rot),
        self.x + self.r * sin(self.rot + pi / 3 * 2),
        self.y - self.r * cos(self.rot + pi / 3 * 2),
        self.x + self.r * sin(self.rot - pi / 3 * 2),
        self.y - self.r * cos(self.rot - pi / 3 * 2)
    }
    lg.polygon('fill', vertices)
    local x = self.x + self.r / 2 * sin(self.rot)
    local y = self.y - self.r / 2 * cos(self.rot)
    local r = self.r / 4
    lg.setColor({1, 1, 1})
    local mark = {
        x + r * sin(self.rot - pi / 3 * 2),
        y - r * cos(self.rot - pi / 3 * 2),
        x + r * sin(self.rot),
        y - r * cos(self.rot),
        x + r * sin(self.rot + pi / 3 * 2),
        y - r * cos(self.rot + pi / 3 * 2)
    }
    lg.line(mark)
    lg.setColor({1, 1, 1})
end
